<html>
    <head>
        <meta charset="utf-8">
        <script src="../dist/claygl.js"></script>
    </head>
    <body style="margin:0px">
        <canvas width="1200" height="640" id="main"></canvas>
        <script type="text/javascript">
            var Shader = clay.Shader;
            var Material = clay.Material;
            var Mesh = clay.Mesh;
            var Cube = clay.geometry.Cube;
            var meshUtil = clay.util.mesh;
            var shaderLibrary = clay.shader.library;

            var renderer = new clay.Renderer({
                canvas: document.getElementById('main')
            });
            renderer.resize(window.innerWidth, window.innerHeight);
            var timeline =  new clay.Timeline();
            timeline.start();

            var shadowMapPass = new clay.prePass.ShadowMap();

            var scene = new clay.Scene;
            var camera = new clay.camera.Perspective({
                    aspect: renderer.getViewportAspect(),
                    far: 500
                });

            var cube = new Cube();
            var shader = shaderLibrary.get('clay.lambert');
            var material = new Material({
                shader: shader
            });

            var root = new clay.Node();
            for(var i = 0; i < 2; i++){
                for(var j = 0; j < 2; j++){
                    for(var k = 0; k < 2; k++){
                        var mesh = new Mesh({
                            geometry: cube,
                            material: material
                        });
                        mesh.scale.set(0.5, 0.5, 0.5);
                        mesh.position.set((i-0.5) * 5, (j-0.5) * 5, (k-0.5)*5);
                        root.add(mesh)
                    }
                }
            }
            scene.add(root);

            var bigCube = new clay.Mesh({
                geometry: new clay.geometry.Cube({
                    inside: true
                }),
                material: new clay.Material({
                    shader: clay.shader.library.get("clay.lambert")
                }),
                culling: false,
                scale: new clay.Vector3(10, 10, 10)
            });
            root.add(bigCube);

            camera.position.set(0, 2, 10);
            camera.lookAt(new clay.Vector3(0, 0, 0));

            var light = new clay.light.Point({
                color: [1.5, 1.5, 1.5],
                shadowResolution: 512,
                intensity: 0.5,
                range: 40,
                castShadow: true
            })
            light.position.set(0.2, 0.2, 0.2);
            scene.add(light);

            var light2 = new clay.light.Point({
                color: [1.5, 1.5, 1.5],
                shadowResolution: 512,
                range: 40,
                intensity: 0.5,
                castShadow: true
            })
            light2.position.set(-0.2, -0.2, -0.2);
            scene.add(light2);

            var elapsedTime = 0;
            timeline.on('frame', function(deltaTime){
                shadowMapPass.render(renderer, scene);
                renderer.render(scene, camera);
                elapsedTime += deltaTime / 1000;
                root.rotation.rotateY(deltaTime / 4000);
                // light.position.x = 0.2 + 7 * Math.sin(elapsedTime + 0.2);
                // light.position.y = 0.2 + 7 * Math.sin(elapsedTime + 0.4);
                // light.position.z = 0.2 + 7 * Math.sin(elapsedTime + 0.3);
            });
        </script>
    </body>
</html>